<template>
  <div class="banner" :style="{
    backgroundColor: config.pageConfig.color,
  }">
    <div :style="{
      marginTop: config.pageConfig.marginTop + 'px',
      marginBottom: config.pageConfig.marginBottom + 'px',
      marginLeft: config.pageConfig.margin + 'px',
      marginRight: config.pageConfig.margin + 'px',
    }">
      <div class="img">
        <div v-for="(item, idx) in config.pageConfig.imgList"
          :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="
            config.pageConfig.style == 3
              ? {
                borderColor: config.pageConfig.borderColor,
                borderWidth: config.pageConfig.borderWidth + 'px',
                borderStyle: 'solid',
              }
              : ''
          " :key="idx">
          <div class="picture-img-contain" :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
          }">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            }" v-if="config.pageConfig.imgList[idx].imgUrl" :src="config.pageConfig.imgList[idx].imgUrl"
              class="picture-img" alt="" />
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            }" v-else src="../../../../../../assets/app/bar/default_picture.png" class="picture-img" alt="" />
          </div>
          <div class="picture-info" :style="{
            backgroundColor: config.pageConfig.imgList[idx].color,
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
          }">
            <h4 :style="{
              fontSize: config.pageConfig.titleSize + 'px',
              color: config.pageConfig.imgList[idx].titleColor,
            }">
              {{ config.pageConfig.imgList[idx].title }}
            </h4>
            <p :style="{
              fontSize: config.pageConfig.subtitleSize + 'px',
              color: config.pageConfig.imgList[idx].subtitleColor,
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }">
              {{ config.pageConfig.imgList[idx].subtitle }}
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "Image",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      style: "1",
      color: "transparent",
      borderColor: "transparent",
      borderWidth: 1,
      marginTop: 0,
      marginBottom: 0,
      margin: 10,
      radiusTop: 0,
      radiusBottom: 0,
      titleSize: 14,
      subtitleSize: 12,
      imgList: [
        {
          title: "主标题",
          subtitle: "副标题",
          titleColor: "#3d404d",
          subtitleColor: "#5e6066",
          color: "#fff",
          imgUrl: "",
          name: "",
          url: "",
        },
        {
          title: "主标题",
          subtitle: "副标题",
          titleColor: "#3d404d",
          subtitleColor: "#5e6066",
          color: "#fff",
          imgUrl: "",
          name: "",
          url: "",
        },
        {
          title: "主标题",
          subtitle: "副标题",
          titleColor: "#3d404d",
          subtitleColor: "#5e6066",
          color: "#fff",
          imgUrl: "",
          name: "",
          url: "",
        },
      ],
    },
  },
});
console.log(config.pageConfig);
let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
const getFlex = (style: string) => {
  if (style == "1") {
    return "text-align:left;";
  } else if (style == "2") {
    return "text-align:center;";
  } else if (style == "3") {
    return "text-align:right;";
  }
};
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  overflow: hidden;
}

.img {
  width: 100%;
  overflow: hidden;
  display: flex;

  >div {
    width: calc(33.3% - 6px);
    margin-right: 6px;
    overflow: hidden;

    &:nth-of-type(3) {
      margin-right: 0px;
    }

    .picture-img-contain {
      width: 113px;

      img {
        display: block;
        height: 113px;
        width: 113px;
        border-radius: 4px 4px 0 0;
      }
    }

    .picture-info {
      text-align: center;
      height: 60px;

      h4 {
        font-weight: 700;
        font-size: 15px;
        line-height: 1;
        padding: 10px 2px 8px;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      p {
        font-size: 12px;
        line-height: 1;
        overflow: hidden;
        padding: 0px 2px 8px;
        box-sizing: border-box;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}

.shadow-style {
  border: none;
  box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
  -webkit-box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
  -moz-box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
}
</style>
